package com.example.permissionsystem1_1.businessFunction.controller.converter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.testReqDto.*;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.testRspDto.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.testReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.testRspModel.*;
import com.example.permissionsystem1_1.common.businessFunction.BaseControllerConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class TestControllerConverter extends BaseControllerConverter {
    //1.新增一条记录
    /**
     * 将reqDto转成reqModel
     * @param reqDto
     * @return
     */
    public static TestInsertReqModel convertDtoToModel(TestInsertReqDto reqDto) {
        if( reqDto == null ) {
            return null;
        }
        TestInsertReqModel reqModel = new TestInsertReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }

    /**
     * 将rspModel转成rspDto
     * @param rspModel
     * @return
     */
    public static TestInsertRspDto convertModelToDto(TestInsertRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestInsertRspDto rspDto = new TestInsertRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //2.新增多条记录
    public static TestInsertBatchReqModel convertDtoToModel(TestInsertBatchReqDto reqDto) {
        if( reqDto == null || reqDto.getInsertBatchReqDtos()==null || reqDto.getInsertBatchReqDtos().size()<=0) {
            return null;
        }
        List<TestInsertReqDto> testInsertReqDtos= reqDto.getInsertBatchReqDtos();
        List<TestInsertReqModel> testInsertReqModels=new ArrayList<>();
        for (TestInsertReqDto testInsertReqDto:testInsertReqDtos) {
            testInsertReqModels.add(convertDtoToModel(testInsertReqDto));
        }
        TestInsertBatchReqModel reqModel = new TestInsertBatchReqModel();
        reqModel.setInsertBatchReqModels(testInsertReqModels);
        return reqModel;
    }
    public static TestInsertBatchRspDto convertModelToDto(TestInsertBatchRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestInsertBatchRspDto rspDto = new TestInsertBatchRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //3.根据id删除一条记录
    public static TestDeleteByIdReqModel convertDtoToModel(TestDeleteByIdReqDto reqDto) {
        if( reqDto == null ) {
            return null;
        }
        TestDeleteByIdReqModel reqModel = new TestDeleteByIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestDeleteByIdRspDto convertModelToDto(TestDeleteByIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestDeleteByIdRspDto rspDto = new TestDeleteByIdRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //4.根据给定的字段值删除符合条件的多条记录
    public static TestDeletesReqModel convertDtoToModel(TestDeletesReqDto reqDto) {
        if( reqDto == null ) {
            return null;
        }
        TestDeletesReqModel reqModel = new TestDeletesReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestDeletesRspDto convertModelToDto(TestDeletesRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestDeletesRspDto rspDto = new TestDeletesRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //5.根据ids批量删除多条记录
    public static TestDeleteBatchByIdsReqModel convertDtoToModel(TestDeleteBatchByIdsReqDto reqDto) {
        if( reqDto == null || reqDto.getIds()==null || reqDto.getIds().size()<=0) {
            return null;
        }
        TestDeleteBatchByIdsReqModel reqModel=new TestDeleteBatchByIdsReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestDeleteBatchByIdsRspDto convertModelToDto(TestDeleteBatchByIdsRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestDeleteBatchByIdsRspDto rspDto = new TestDeleteBatchByIdsRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //6.根据id修改一条记录
    public static TestUpdateByIdReqModel convertDtoToModel(TestUpdateByIdReqDto reqDto) {
        if( reqDto == null || reqDto.getId()==null ) {
            return null;
        }
        TestUpdateByIdReqModel reqModel = new TestUpdateByIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestUpdateByIdRspDto convertModelToDto(TestUpdateByIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestUpdateByIdRspDto rspDto = new TestUpdateByIdRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //7.根据指定的byTestPo中的属性为选择条件,按照setTestPo中的属性进行修改符合条件的多条记录
    public static TestUpdatesReqModel convertDtoToModel(TestUpdatesReqDto reqDto) {
        if( reqDto == null || reqDto.getByReqDto()==null || reqDto.getSetReqDto()==null ) {
            return null;
        }
        TestUpdateByIdReqModel byReqModel=new TestUpdateByIdReqModel();
        BeanUtils.copyProperties(reqDto.getByReqDto(), byReqModel);
        TestUpdateByIdReqModel setReqModel=new TestUpdateByIdReqModel();
        BeanUtils.copyProperties(reqDto.getSetReqDto(), setReqModel);

        TestUpdatesReqModel reqModel = new TestUpdatesReqModel();
        reqModel.setByReqModel(byReqModel);
        reqModel.setSetReqModel(setReqModel);

        return reqModel;
    }
    public static TestUpdatesRspDto convertModelToDto(TestUpdatesRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestUpdatesRspDto rspDto = new TestUpdatesRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //8.根据指定多个ids,来批量修改多条记录
    public static TestUpdateBatchByIdsReqModel convertDtoToModel(TestUpdateBatchByIdsReqDto reqDto) {
        if( reqDto == null || reqDto.getIds()==null || reqDto.getIds().size()<=0 ) {
            return null;
        }
        TestUpdateBatchByIdsReqModel reqModel=new TestUpdateBatchByIdsReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestUpdateBatchByIdsRspDto convertModelToDto(TestUpdateBatchByIdsRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestUpdateBatchByIdsRspDto rspDto = new TestUpdateBatchByIdsRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //9.根据指定id查询一条记录
    public static TestSelectByIdReqModel convertDtoToModel(TestSelectByIdReqDto reqDto) {
        if( reqDto == null || reqDto.getId()==null ) {
            return null;
        }
        TestSelectByIdReqModel reqModel=new TestSelectByIdReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestSelectByIdRspDto convertModelToDto(TestSelectByIdRspModel rspModel){
        if (rspModel == null) {
            return null;
        }
        TestSelectByIdRspDto rspDto = new TestSelectByIdRspDto();
        BeanUtils.copyProperties(rspModel, rspDto);
        return rspDto;
    }
    //10.根据指定的条件查询符合条件的多条记录
    public static TestSelectsReqModel convertDtoToModel(TestSelectsReqDto reqDto) {
        if(reqDto==null){
            reqDto=new TestSelectsReqDto();
        }
        TestSelectsReqModel reqModel=new TestSelectsReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestSelectsRspDto convertModelToDto(TestSelectsRspModel rspModel){
        if (rspModel == null) {
            return null;
        }

        List<TestSelectByIdRspDto> selectByIdRspDtos=new ArrayList<>();
        List<TestSelectByIdRspModel> selectByIdRspModels=rspModel.getSelectByIdRspModels();
        for (TestSelectByIdRspModel selectByIdRspModel:selectByIdRspModels) {
            selectByIdRspDtos.add(convertModelToDto(selectByIdRspModel));
        }

        TestSelectsRspDto rspDto = new TestSelectsRspDto();
        rspDto.setSelectByIdRspDtos(selectByIdRspDtos);
        return rspDto;
    }
    //11.根据多个id查询多条记录
    public static TestSelectBatchByIdsReqModel convertDtoToModel(TestSelectBatchByIdsReqDto reqDto) {
        if(reqDto==null || reqDto.getIds()==null || reqDto.getIds().size()<=0){
            return null;
        }
        TestSelectBatchByIdsReqModel reqModel=new TestSelectBatchByIdsReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestSelectBatchByIdsRspDto convertModelToDto(TestSelectBatchByIdsRspModel rspModel){
        if (rspModel == null) {
            return null;
        }

        List<TestSelectByIdRspDto> selectByIdRspDtos=new ArrayList<>();
        List<TestSelectByIdRspModel> selectByIdRspModels=rspModel.getSelectByIdRspModels();
        for (TestSelectByIdRspModel selectByIdRspModel:selectByIdRspModels) {
            selectByIdRspDtos.add(convertModelToDto(selectByIdRspModel));
        }

        TestSelectBatchByIdsRspDto rspDto = new TestSelectBatchByIdsRspDto();
        rspDto.setSelectByIdRspDtos(selectByIdRspDtos);
        return rspDto;
    }
    //12.分页查询多条记录
    public static TestSelectPageReqModel convertDtoToModel(TestSelectPageReqDto reqDto) {
        if(reqDto==null){
            return null;
        }
        TestSelectPageReqModel reqModel=new TestSelectPageReqModel();
        BeanUtils.copyProperties(reqDto, reqModel);
        return reqModel;
    }
    public static TestSelectPageRspDto convertModelToDto(TestSelectPageRspModel rspModel){
        if (rspModel == null || rspModel.getSelectByIdPageRspModels()==null) {
            return null;
        }
        TestSelectPageRspDto rspDto=new TestSelectPageRspDto();
        IPage<TestSelectByIdRspModel> ipageModel=rspModel.getSelectByIdPageRspModels();
        List<TestSelectByIdRspModel> selectByIdRspModels=ipageModel.getRecords();
        List<TestSelectByIdRspDto> selectByIdRspDtos=new ArrayList<>();
        if(selectByIdRspModels.size()>0){
            for(TestSelectByIdRspModel selectByIdRspModel:selectByIdRspModels){
                selectByIdRspDtos.add(convertModelToDto(selectByIdRspModel));
            }
        }
        IPage<TestSelectByIdRspDto> ipageDto=new Page<>(ipageModel.getCurrent(), ipageModel.getSize(),ipageModel.getTotal());
        ipageDto.setRecords(selectByIdRspDtos);
        rspDto.setSelectByIdPageRspDtos(ipageDto);
        return rspDto;
    }

}
